Hey, next question for nosql is how can I do an update to a full document?
What I want to be able to do is just upload the json for my Monsters metaCollection from my tool (mentioned in another question...working on getting the sdk working with my c# wpf tool)
This is what I was trying, I can get the monsters from the json and just grab the old Id for continuity but I can't make the collection itself save the new data for some reason...I've tried findAndModify, Update and none of them seem to work...
I can't be too far off right? (DB's and nosql is still pretty new, been lots of fumbling about trying to get things to work)
Best Answer
T
Travis Evashkevich
said
over 5 years ago
I got it to work like right after I posted haha. Had been staring at it and documentation for too long and missed something
Anyways for future ref, I got it like this:
var newMonsterData = [];
newMonsterData = monsterData;
//copy previous ID of document for consistency
newMonsterData["_id"] = monsters["_id"];
monsters = newMonsterData;
monsterCollec.save(monsters);
}
I could probably put it onto like 2 lines but haven't had a chance to go and refactor yet.
I got it to work like right after I posted haha. Had been staring at it and documentation for too long and missed something
Anyways for future ref, I got it like this:
var newMonsterData = [];
newMonsterData = monsterData;
//copy previous ID of document for consistency
newMonsterData["_id"] = monsters["_id"];
monsters = newMonsterData;
monsterCollec.save(monsters);
}
I could probably put it onto like 2 lines but haven't had a chance to go and refactor yet.
Customer Support
said
over 5 years ago
Hey Travis,
So findandmodify is what i would suggest here, but its hard to tell why that isn't working without seeing how you are using it. Maybe you can paste in an example of how you are using it? But i do see a possible problem here though. Your 'monsters' variable is a doc in the collection so it would have a JSON format. But your 'newMonsterData' variable is an array, not a form, so this might do something strange when you try add element to it. You could try...
var newMonsterData = {};
instead of ...
var newMonsterData = [];
That might work when you try to pass it back into the findandmodifty method.
Travis Evashkevich
Hey, next question for nosql is how can I do an update to a full document?
What I want to be able to do is just upload the json for my Monsters metaCollection from my tool (mentioned in another question...working on getting the sdk working with my c# wpf tool)
This is what I was trying, I can get the monsters from the json and just grab the old Id for continuity but I can't make the collection itself save the new data for some reason...I've tried findAndModify, Update and none of them seem to work...
I can't be too far off right? (DB's and nosql is still pretty new, been lots of fumbling about trying to get things to work)
I got it to work like right after I posted haha. Had been staring at it and documentation for too long and missed something
Anyways for future ref, I got it like this:
var newMonsterData = [];
newMonsterData = monsterData;
//copy previous ID of document for consistency
newMonsterData["_id"] = monsters["_id"];
monsters = newMonsterData;
monsterCollec.save(monsters);
}
I could probably put it onto like 2 lines but haven't had a chance to go and refactor yet.
1 person has this question
- Oldest First
- Popular
- Newest First
Sorted by Newest FirstCustomer Support
Travis Evashkevich
I got it to work like right after I posted haha. Had been staring at it and documentation for too long and missed something
Anyways for future ref, I got it like this:
var newMonsterData = [];
newMonsterData = monsterData;
//copy previous ID of document for consistency
newMonsterData["_id"] = monsters["_id"];
monsters = newMonsterData;
monsterCollec.save(monsters);
}
I could probably put it onto like 2 lines but haven't had a chance to go and refactor yet.
Customer Support
So findandmodify is what i would suggest here, but its hard to tell why that isn't working without seeing how you are using it. Maybe you can paste in an example of how you are using it?
But i do see a possible problem here though.
Your 'monsters' variable is a doc in the collection so it would have a JSON format.
But your 'newMonsterData' variable is an array, not a form, so this might do something strange when you try add element to it.
You could try...
var newMonsterData = {};
instead of ...
var newMonsterData = [];
That might work when you try to pass it back into the findandmodifty method.
you could try this....
monsterData._id = monsters._id;
Spark.metaCollection('Monsters').findAndModify(
{ '_id' : monsters._id },
monsterData
);
and you can skip the new variable completely.
Just check in the test-harness that the correct variables are updating.
Let me know if that makes sense
Sean
-
Documentation Notes
-
Design issues with user events
-
Using NoSQL
-
Runtime Collections vs Metadata Collections
-
Anonymous authentication from browser app
-
Modules
-
Movement With Unity
-
Problem with url parameters for downloadables
-
Querying NoSql GameSparks database
-
Challenge accesType
See all 2486 topics