As the title says, I'm not able to remove the _id from a query.
My cloud code is:
var unitsCollection = Spark.metaCollection('Units');
var unitsCursor = unitsCollection.find({ "_id" : 0 });
var unitsList = [];
while(unitsCursor.hasNext())
{
var unit = unitsCursor.next(); //value is now a single json document
unitsList.push(unit);
}
Spark.setScriptData("units_Data", unitsList);
Each document under Units meta-collection has this Json format:
If I remove the "{ "_id" : 0 }" inside Find() it works fine but it returns everything including _id which I don't need and breaks my Json-To-UnityObject parser.
I've tried different things but I can't make it work. Am I missing something?
Best Answer
C
Customer Support
said
about 5 years ago
Hi Ivan,
The issue here is you're using the field limit as your query. Try the following and it should return the documents without the id.
var unitsCursor = unitsCollection.find({},{ "_id" : 0 });
Meta collections are read/write on preview so you'll be able to test them in preview. I was just warning you that if your code was updating a meta collection in preview it would not work in live. If the code itself is simply for setting up your meta collection before publishing to live then that should be fine.
It works fine but it also returns the annoying _id
About "Meta Collections are read only on live."
Does that mean that I'm forced to publish the game (go live) even when it's still in development to be able to read MetaCollections? It doesn't make sense to me. I want to make sure that all my metadata is parsed and cached correctly before going live.
Also, why using find() works and with find({ "_id" : 0 }) doesn't?
I have the feeling that I'm missing a paramenter or something.
Customer Support
said
about 5 years ago
Answer
Hi Ivan,
The issue here is you're using the field limit as your query. Try the following and it should return the documents without the id.
var unitsCursor = unitsCollection.find({},{ "_id" : 0 });
Meta collections are read/write on preview so you'll be able to test them in preview. I was just warning you that if your code was updating a meta collection in preview it would not work in live. If the code itself is simply for setting up your meta collection before publishing to live then that should be fine.
Regards,
Liam
1 person likes this
I
Ivan Martinez
said
about 5 years ago
Ohh I see, I knew I was missing something...
Now it works fine. Also, good to know the live/preview thing.
Ivan Martinez
As the title says, I'm not able to remove the _id from a query.
My cloud code is:
Each document under Units meta-collection has this Json format:
The code returns me an empty list.
If I remove the "{ "_id" : 0 }" inside Find() it works fine but it returns everything including _id which I don't need and breaks my Json-To-UnityObject parser.
I've tried different things but I can't make it work. Am I missing something?
Hi Ivan,
The issue here is you're using the field limit as your query. Try the following and it should return the documents without the id.
Meta collections are read/write on preview so you'll be able to test them in preview. I was just warning you that if your code was updating a meta collection in preview it would not work in live. If the code itself is simply for setting up your meta collection before publishing to live then that should be fine.
Regards,
Liam
- Oldest First
- Popular
- Newest First
Sorted by Oldest FirstCustomer Support
Hi Ivan,
Is this in preview or on live ? Meta Collections are read only on live.
Regards,
Liam
Ivan Martinez
Hello Liam.
The game is in Preview.
This is the Event Response I get when I try to filter the _id out:
( https://gyazo.com/5e377a3150968ad6f37d4e344a8a36d6 )
And this when I remove the filter parameter in Find():
( https://gyazo.com/6ec1d01bf683ffc5b22790c8065bbe51 )
It works fine but it also returns the annoying _id
About "Meta Collections are read only on live."
Does that mean that I'm forced to publish the game (go live) even when it's still in development to be able to read MetaCollections? It doesn't make sense to me. I want to make sure that all my metadata is parsed and cached correctly before going live.
Also, why using find() works and with find({ "_id" : 0 }) doesn't?
I have the feeling that I'm missing a paramenter or something.
Customer Support
Hi Ivan,
The issue here is you're using the field limit as your query. Try the following and it should return the documents without the id.
Meta collections are read/write on preview so you'll be able to test them in preview. I was just warning you that if your code was updating a meta collection in preview it would not work in live. If the code itself is simply for setting up your meta collection before publishing to live then that should be fine.
Regards,
Liam
1 person likes this
Ivan Martinez
Ohh I see, I knew I was missing something...
Now it works fine. Also, good to know the live/preview thing.
Thanks Liam!
-
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 2487 topics