This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
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


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: 1726
    
  14

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.
 
GeeCON Prague 2014
 
subject: Problem in updating commection in MongoDb