wood burning stoves*
The moose likes MongoDB and the fly likes Problem in updating commection in MongoDb Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » MongoDB
Bookmark "Problem in updating commection in MongoDb" Watch "Problem in updating commection in MongoDb" New topic
Author

Problem in updating commection in MongoDb

Vishal Baid
Ranch Hand

Joined: Jul 18, 2012
Posts: 42
    
    1
My Collection
> db.rec1.find().pretty()
{
"_id" : ObjectId("537b4d79f8b58b56f86d0af8"),
"carrierCode" : "AA",
"carrierName" : "Americal Airline Inc",
"timing" : [
{
"arrival" : {
"date" : 200514,
"time" : 1628
}
},
{
"depart" : {
"date" : 200514,
"time" : 2000
}
}
]
}

I want to change the value of depart time to 1800. For this I am using following :
db.rec1.update({"carrierCode":"AA","timing.depart.time":2000},{$set:{"timing.$.depart":{"time":1800}}})

But this query give me undesired result.

> db.rec1.find().pretty()
{
"_id" : ObjectId("537b4d79f8b58b56f86d0af8"),
"carrierCode" : "AA",
"carrierName" : "Americal Airline Inc",
"timing" : [
{
"arrival" : {
"date" : 200514,
"time" : 1628
}
},
{
"depart" : {
"time" : 1800
}
}
]
}

In this collection, depart time is change. But this remove the date field. Please help me guys.
Just now i completed m101j mongoDB course doing some practice work for a project.

Thanks in advance.
Vishal Baid
Ranch Hand

Joined: Jul 18, 2012
Posts: 42
    
    1
yupiii

I got the answer. I was trying this from last 5-6 hrs. Reading lot of things.
Now I got the solution which i want to share with you guys :



I know this is a small problem for lot of people. But As i am newbie. So for me its time for celebration. I mean to say near about achievement.
chris webster
Bartender

Joined: Mar 01, 2009
Posts: 1616
    
  13

Well done for solving your problem, and I gave you a JavaRanch cow for sharing the solution so promptly.


No more Blub for me, thank you, Vicar.
 
Consider Paul's rocket mass heater.
 
subject: Problem in updating commection in MongoDb
 
Similar Threads
Pattern for updating multiple rows in an array attribute.
Map Reducer with MongoDB hadoop driver throws Exception!
update query in mongodb?
how to select key value of mongodb document?
MongoDB Patterns