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)
})
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).