简体   繁体   English

MongoDB与RethinkDB的r.row等效吗?

[英]What is MongoDB's equivalent to RethinkDB's r.row?

The project I am working on uses MongoDB, but I usually use RethinkDB. 我正在处理的项目使用MongoDB,但我通常使用RethinkDB。 I am trying to write an operation that will take the current value of a document's property and subtract 1 from it. 我正在尝试编写一个将获取文档属性的当前值并从中减去1的操作。 In reQL this would be r.db('db').table('table').get('documentId').update({propToUpdate: r.row('propToUpdate').sub(1)}) . 在reQL中,这将是r.db('db').table('table').get('documentId').update({propToUpdate: r.row('propToUpdate').sub(1)}) How can I preform the same function in MongoDB? 如何在MongoDB中执行相同的功能?

I think you can use $inc operator: 我认为您可以使用$ inc运算符:

db.products.update(
   { sku: "abc123" },
   { $inc: { quantity: -1} }
);

As an example extract from here . 作为示例,请从此处摘录。

Where "db" is the database, (eg use myDatabase), "products" is the name of the collection you want to query, "sku" is the field you are querying and "quantity" is the field you want to increment/decrement. 其中“ db”是数据库(例如,使用myDatabase),“ products”是要查询的集合的名称,“ sku”是要查询的字段,“ quantity”是要增加/减少的字段。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM