• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Problem in updating commection in MongoDb

 
Ranch Hand
Posts: 42
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Bartender
Posts: 2407
36
Scala Python Oracle Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well done for solving your problem, and I gave you a JavaRanch cow for sharing the solution so promptly.
 
Slime does not pay. Always keep your tiny ad dry.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic