• Post Reply Bookmark Topic Watch Topic
  • New Topic

Delete a document using findOneDelete  RSS feed

 
rajesh naga
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • 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
 
VikasKumar Gupta
Greenhorn
Posts: 18
1
  • Mark post as helpful
  • send pies
  • 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 is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!