如何检查文档是否已更新或插入到MongoDB中 [英] how to check if an document is updated or inserted in MongoDB
本文介绍了如何检查文档是否已更新或插入到MongoDB中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我只是想知道是否有一种方法可以在Java中进行upsert操作之后检查给定的文档是否已更新或插入到MongoDB中:
I'm just wondering if there's way to check if a given document is updated or inserted in MongoDB after a upsert operation in Java:
DBCollection col = getCollection();
// either this
col.findAndModify(query, null, null, false, contact, false, true);
// or this
WriteResult wr = col.update(query, contact, true, false);
推荐答案
1-> step : set the profiler using > db.setProfilingLevel(2);
on the document target.
2-> run this query
db.system.profile.find({},{ts:1, op:1, ns:1}).sort({ts: -1}).forEach(printjson);
它将在op
属性中显示给定文档是否已更新或插入,并且ns
是文档名称. ts
查询运行时.
it will show you in the op
attribute if the given document is updated or inserted and ns
is the document name. ts
when the query run.
这篇关于如何检查文档是否已更新或插入到MongoDB中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文