Java的MongoDB:检索和删除文档

In this tutorial we will learn how we can retrieve or fetch data from any document stored in a collection and how to delete any existing document stored in any collection.

在本教程中,我们将学习如何从集合中存储的任何文档中检索或获取数据,以及如何删除任何集合中存储的现有文档。

These functions are equivalent to SELECT and DELETE query in MySQL

这些功能等效于MySQL中的SELECTDELETE查询

检索文件 (Retrieve a Document)

If we want to retrieve data against field friends from document with _id xyz123, it can be done with the help of below code snippet:

如果我们想使用_id xyz123从文档中检索针对领域friends数据,则可以在以下代码段的帮助下完成:

Retrieve Data in MongoDB

The output produced on console is:

在控制台上产生的输出是:

Retrieve Data in MongoDB

删除文件 (Delete a Document)

Now, in our friends field, we have data as "andy", "John" and "Amit". If we want to remove "John" from the list, we can with the help of the below code.

现在,在我们的“ 朋友”字段中,我们的数据为“ andy”“ John”“ Amit” 。 如果要从列表中删除“ John” ,可以在以下代码的帮助下进行。

Delete Data in MongoDB

The output of the query is:

查询的输出是:

Delete Data in MongoDB

"John" is removed from the field friends.

“约翰”被从田野友人中删除。

翻译自: https://www.studytonight.com/mongodb/retrieve-delete-mongodb

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值