mongo-provider icon indicating copy to clipboard operation
mongo-provider copied to clipboard

Referencing other object id

Open truemetal opened this issue 8 years ago • 4 comments

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:

1

This code:

var post = Post(userId: Node(["$oid" : user.id!]), content: content)
try post.save()

Produces this:

2

But how do I achieve this?

proper

truemetal avatar Mar 27 '17 16:03 truemetal

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(...)

tanner0101 avatar Mar 29 '17 17:03 tanner0101

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 avatar Mar 29 '17 19:03 vzsg

@vzsg that seems like a great solution

tanner0101 avatar Mar 29 '17 22:03 tanner0101

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?

ankurp avatar Dec 10 '17 17:12 ankurp