mongo-provider
mongo-provider copied to clipboard
Referencing other object id
This is more of a question with a potential of becoming a feature request.
This code:
var post = Post(userId: Node(user.id!, content: content)
try post.save()
Produces this:
This code:
var post = Post(userId: Node(["$oid" : user.id!]), content: content)
try post.save()
Produces this:
But how do I achieve this?
Node doesn't have an identifier type so I don't think it's possible to do through the Fluent API currently.
We'd need to decide on some method for signaling an object id (perhaps oid: before the string?)
As a workaround, you can do (database.driver as? MongoDriver)?.raw(...)
Most Mongo commands use $something as object keys to separate them from JSON data. I think it would be a clean strategy for the driver to do the same, and @truemetal's example code (from "This code:") should work automatically.
@vzsg that seems like a great solution
I have a sample application where a ShoppingList model has many Item objects. When I create an Item with the shopping_list_id, then the shopping list model is not able to query to fetch all items that it owns. Here is the repo which has the code https://github.com/ankurp/ShoppingListServer
Does Mongo Provider support parent child relation and is it able to query all children from the database?