0

Code below. The outcome of this is that each document ends up with the array created from just one of the documents. In other words, "twindex" for each document is the same array. Any ideas what boneheaded thing I'm overlooking?

var cursor = db.splittest.find();

cursor.forEach(

    function(x) {

        db.splittest.update({}, {"$set" :  {"x.twindex" : x.content.split(" ")}}, true, true)

    })

1 Answer 1

2

By specifying 'true, true' you're doing upserts on every document. Leave them out and it will default to false (so you don't need to add them in the code).

db.splittest.update({_id:x._id}, {"$set" :  {"x.twindex" :x.content.split(" ")}})
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! I was unclear about the upsert function from the beginning. Totally did the trick.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.