Questions tagged [findandmodify]
96 questions
1
vote
1 answer
Find and replace string in HTML using PHP DOM Parser
How do you find and replace a string in html page using the native PHP DOM Parser?
Example string to find: "the company has been growing for the past 5 months";
The parent is a full HTML page for example and the immediate…

user3857924
- 86
- 3
- 15
1
vote
1 answer
mongo db add subdocuments from another collection
I have two collections awards teams have won and a list of teams. I want to ETL the whole of awards into the other (teams) as subdocuments with some minor transformations, but I only get one subdocument from the awards into teams.
Here is the code…

Glenn McMillen
- 13
- 2
1
vote
1 answer
findAndModify usage in node.js/MongoDb
I have a collection which shows a list of users with their favorite movies.
Here is a sample dataset ...
{
"_id" : ObjectId("545c08dcc4d2b8a0243dd4db"),
"mail" : "mickey@mouse.com",
"name" : "Mickey Mouse",
…

EnnioMorricone
- 37
- 1
- 5
1
vote
1 answer
findAndModify Error in mongodb - nodejs - error code 17287
I am getting following error :
MongoError: exception: nextSafe(): { $err: "Can't canonicalize query:
B adValue bad sort specification", code: 17287 }
functions.getNextIndex = function(callback){
db.collection('counters').findAndModify(
…

Mj.
- 321
- 1
- 6
- 13
1
vote
1 answer
Can I use something like findAndModify on a deep nested document with MongoDB?
I have the Collection contexts with documents like the following in my MongoDB (a context has some users with roles)
{
"__v" : 0,
"_id" : ObjectId("53dea71a713d636e1fea705a"),
"name" : "team4",
"users" : [
{
…

koalabruder
- 2,794
- 9
- 33
- 40
1
vote
3 answers
Using existing document data with new info in MongoDB FindAndModify
A document has the following schema when an order is created:
{order:1,startTime:1402442830110}
When an order is finished, a db.collection.findAndModify() operation is processed to set the endTime resulting in a document like…

cml
- 107
- 2
- 12
1
vote
1 answer
MongoDB - $set with findAndModify or update on embedded documents
I would like to use findAndModify to upsert the fields of an embedded document. For example, if I were to insert this document.
{
'name':'Goku',
'level':9000,
'family':{
'son':'Grandpa Gohan',
'wife':'Chi Chi'
}
}
Then at…
user1965005
1
vote
1 answer
updating/inserting subdocument mongodb
I clearly don't understand how I update / insert a subdocument in an existing document.
I tried the following:
query = aCollection.find_one({stuffToFind})
aCollection.update(query,
{"$set": {"subDoc" : {"1" :…

Codehai
- 524
- 1
- 7
- 27
1
vote
1 answer
Find all .htaccess files in all user sub-directories and add a string to it
I want to find all ".htaccess" files (if the file exist, if not create one) for all user accounts in a whole string of possible sub-directories underneath "public_html" (but not public_html). Basically find it in anything that remotely resembles a…

Eva
- 13
- 5
1
vote
1 answer
Mongodb findAndModify embedded document - how do you know which one you've modified?
findAndModify in mongodb is great, but I am having a little trouble knowing which embedded document I modified.
Here is an example where a Post embeds_many Comments. (I'm using Mongoid ORM but the question is generic to any MongoDB setup).
begin
…

Brian Armstrong
- 19,707
- 17
- 115
- 144
1
vote
2 answers
using findAndModify in mongodb using grails gorm
I need to use findAndModify in my application with grails and mongoDB.
I used this code :
public static String getNextId(DB db, String seq_name) {
String sequence_collection = "seq"; // the name of the sequence collection
String sequence_field =…

zorro6064
- 484
- 2
- 7
- 18
1
vote
2 answers
MongoDB Sharding findAndModify
I am attempting to shard my database, but I am having an issue with findAndModify
I have a schema that looks like this (myCollection):
{
"_id": "508206a9f6ded00c50f59469"
"DatabaseId" : 91,
"TypeId" : "5e62603c-8",
"ItemId" : "734",
…

ehftwelve
- 2,787
- 2
- 20
- 25
1
vote
1 answer
MongoDB: Capped collection findAndModify
I'm trying to atomically insert an empty document if the capped collection is empty or return the last naturally sorted document if not empty. Can I do this with findAndModify?
db.collection.findAndModify({
query: { _id: { $exists: true }},
…

scttnlsn
- 2,976
- 1
- 33
- 39
1
vote
2 answers
Is mongoDB's findAndModify "transaction-save"
i know, there is no transaction support on mongo DB. But now i need to read an value of an document, increment by 1 and write the new value.
Or - different way:
Update an element and read the value at the same time.
For this i like to use find and…

The Bndr
- 13,204
- 16
- 68
- 107
0
votes
0 answers
Mongodb concurrent updates of counter do not maintain consistency with findAndModify
We have counter stored in mongodb and multiple threads are trying to read and increment the counter. Can one thread override the value of other with findAndModify(). For example counter value is 1 if 6 threads increasing the conuter concurrently by…

user3184674
- 11
- 2