I am trying to query a collection inside an App Service function.
My _id is a BSON.UUID.
When I receive my data, I received an empty object for my _id.
For instance:
{“_id”:{},“name”:“Anne”,“phone”:“21987654321”}
That also happens when I have a function triggered by insertions. I receive my document but the _id is an empty object.
It also happens with other “different” types, like decimal 128.
Could someone help me?
Is it really an empty object? Or your print routine is not able to print the value correctly? The fact that
seems to indicate a bug in your print routine.
I am not sure what the problem is, but I can’t access what is inside _id.
When I try do to something like
new BSON.UUID(obj._id)
I get “TypeError: Value is not an object: undefined”
When I log obj._id, I get [object Binary]
When I log JSON.stringify(oldUsedId._id), I get {}
Why is obj in
and oldUsedId in
What is the code that produce
Hello Mariana, I issued a similar problem. There is some difference when we use Binary data with MongoDB and try to manipulate it with JSON. Maybe you can try to use EJSON instead of JSON https://www.mongodb.com/docs/atlas/app-services/data-api/data-formats/#binary.
It works for me hope it could works for you too.
@Mariana_Zagatti, could we have a follow-up on this? If a solution was provided here, please mark the post as the solution, otherwise please share the solution. This is the best way to keep the forum useful to everyone.
Too bad we do not have a follow up from @Mariana_Zagatti.
Hello. I’m facing the same kind of issue.
From an atlas function, if I retrieve a document with some attributes stored as UUID, I can’t seem to retrieve the string representation of that UUID.
I have a (simplified) document as follow:
{ _id: UUID('ecacaa38-79b2-5635-87fa-c9176772862d')}
Tried the following:
const document = ....
console.log(document._id) => [object Binary]
console.log(document._id.toString()) => [object Binary]
console.log(JSON.stringify(document._id)) => {}
console.log(EJSON.stringify(document._id)) => {"$binary": {"base64": "xxxxx", "subType": "04"}}
To be noted that using a simple node script locally with mongodb dependency, I have no issue for the exact same document. Going with document._id.toString() will give me the string representation of that UUID.
Any advice on how to use the UUID inside an Atlas function?
I successfully managed the read operations by parsing data into objects, converting them into hexadecimal buffers using base64, and organizing the resultant string.
However, my attempts to handle insert/update operations using UUIDs or decimal128 formats were not successful.
Could you please provide a sample code of your conversions?
Struggling with this. Tried to decode the base64 from the EJSON log, but it’s only giving me some weird characters…