This week's book giveaway is in the Cloud/Virtualizaton forum.
We're giving away four copies of Mesos in Action and have Roger Ignazio on-line!
See this thread for details.
Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Problem in updating commection in MongoDb

 
Vishal Baid
Ranch Hand
Posts: 42
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 42
1
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2407
32
Linux Oracle Postgres Database Python Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well done for solving your problem, and I gave you a JavaRanch cow for sharing the solution so promptly.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic