发布于 2015-09-14 14:56:06 | 157 次阅读 | 评论: 0 | 来源: 网络整理

db.collection.remove(query, justOne)

The remove method removes documents from a collection.

The remove() method can take the following parameters:

参数:
  • query (document) – Optional. Specifies the deletion criteria using query operators. Omit the query parameter or pass an empty document (e.g. {} ) to delete all documents in the collection.
  • justOne (boolean) – Optional. A boolean that limits the deletion to just one document. The default value is false. Set to true to delete only the first result.

注解

You cannot use the remove() method with a capped collection.

Consider the following examples of the remove method.

  • To remove all documents in a collection, call the remove method with no parameters:

    db.products.remove()
    

    This operation will remove all the documents from the collection products.

  • To remove the documents that match a deletion criteria, call the remove method with the query criteria:

    db.products.remove( { qty: { $gt: 20 } } )
    

    This operation removes all the documents from the collection products where qty is greater than 20.

  • To remove the first document that match a deletion criteria, call the remove method with the query criteria and the justOne parameter set to true or 1:

    db.products.remove( { qty: { $gt: 20 } }, true )
    

    This operation removes all the documents from the collection products where qty is greater than 20.

注解

If the query argument to the remove() method matches multiple documents in the collection, the delete operation may interleave with other write operations to that collection. For an unsharded collection, you have the option to override this behavior with the $isolated isolation operator, effectively isolating the delete operation and blocking other write operations during the delete. To isolate the query, include $isolated: 1 in the query parameter as in the following example:

db.products.remove( { qty: { $gt: 20 }, $isolated: 1 } )
最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务