I'm new to this whole JS/Mongo thing and trying to find the best approach here.
Basically I have a collection of items, and I want to lock a subset of them to a specific user. So step by step
lock='')lock='user.name'Ok, likely there will be some race-condition issues here, but for the time being, let's not worry about that. The main issue is that once this is completed user2 should not be able to find/lock the same items.
In the Mongoose docs I found the findOneAndUpdate which seems to do exactly what I want, except it only handles one item.
What are the options here?
If the api support you are searching for is not available you can try this. First list out all the data that is matching with your condition and then on that filtered data apply the update .
I am giving one example :
Query query= query.addCriteria(Criteria.where("page_id").is(new Long("1234")));
List<PageWidgetDetails> pageWidgetDetailsList = mongo.find(query, PageWidgetDetails.class);
for (PageWidgetDetails pageWidgetDetailsObj : pageWidgetDetailsList) {
String widget_id=pageWidgetDetailsObj.getWidgetId();
query=new Query(Criteria.where("widget_id").is(widget_id));
update=new Update();
update.set("widget_description", "blah blah ....");
mongo.upsert(query, update, PageWidgetDetails.class);
}