• 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
  • Ron McLeod
  • Liutauras Vilda
  • Paul Clapham
  • paul wheaton
Sheriffs:
  • Tim Cooke
  • Devaka Cooray
  • Rob Spoor
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:

Delete a document using findOneDelete

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

Tried to delete a document in a field of the collection.
It works only without specify query.
If specify query,it failed.

Anyone check please the below syntax are right one


> db.My_First_Collection.findOneAndDelete({ query: { UserName: "NewArk"} } )
null
> db.My_First_Collection.findOneAndDelete({ query: { UserName: "NewArk" } } )
null
> db.My_First_Collection.findOneAndDelete( { UserName: "NewArk" }  )
{
       "_id" : ObjectId("5860bf9a487cb401d97af156"),
       "UserName" : "NewArk",
       "Password" : "Obama",
       "UserId" : 2,
       "CreationDate" : "Mon Dec 26 2016 12:28:34 GMT+0530 (India Standard Time
)"
}
>

Any suggestions

Thanks
 
Greenhorn
Posts: 26
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dear Rajesh,

Please follow the link and find the correct usage of the command.

https://docs.mongodb.com/manual/reference/method/db.collection.findOneAndDelete/

Regards,
Vikas
 
It's hard to fight evil. The little things, like a nice sandwich, really helps. Right tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic