mongodb - Monodb database migration with embedded query -
Currently the messages
objects in my database are set as the following. "Message": "Message": "System", "Message": "Sean Collahne has entered the room.", "Time": 1406479167270, "Type": "System_ Message", "Room I want to migrate my data basically so that in each message the room id
will be displayed in every message: "Helloorom", "_ID": "4IHHHMMGJNTTHWW"}
Yes, that indicates in the appropriate room. Currently it is done with the room
attribute, which I see for some reason in my own way.
The objects in my room are set in such a way.
{"_id:" xxxxxxxxx "room_name:" "testroom"}
So I was hoping that there was a way to run a liner The correct room id
is set for the current message based on the current room
attribute which will simply add
I was thinking like something ..
db.messages.update ({}, {$ set: {roomId: db.rooms.findOne ({room_name: cell}) ._ id}})
Now, I'm getting a room is not defined, which makes sense but I do not think this is right, and this It is possible that one-line queries may not be possible.
As you found, this is not possible in a one-line query because you can not access data from two collections Need to join
Here is an example that Mongo
shell:
db.messages.find ({roomId: {$ exists: wrong}}) .for eka (function (room) {var roomId = db.rooms (one room: name: room.room}); if (room id.id) {db.messages.update ({_id: room._id}, { $ Set: {roomId: roomId._id}}}})
You can clear this with some error checking, and for updates to large archives (MongoDB 2.6 + ).
Comments
Post a Comment