@zynchro wrote:
Simply put, what I need to achieve is posts/likes/comments system; all stored in Mongo.
My earlier approach was to create post, comments, likes schema separately (and connect them) - but a more efficient way would be to have likes inside the post object.
eg:
{ "_id": ObjectId("54bb201aa3a0f26f885be2a3"), "photo": "grabembythepu55.png", "post": "Great, again.", "likeCount": 0, "likes": [] }
and then on POST /like this needs to happen on the db;
db.photos.update( { "_id": ObjectId("54bb201aa3a0f26f885be2a3"), "likes": { "$ne": ObjectId("54bb2244a3a0f26f885be2a4") } }, { "$inc": { "likeCount": 1 }, "$push": { "likes": ObjectId("54bb2244a3a0f26f885be2a4") } } )
so that duplicates would not happen for the same user.
However I am having trouble using $inc and $push via the API docs / using custom API script.
I saw on this response that mongoDB operators are not supported, but in this blog post it uses $set and $inc.
Any pointers how I can implement this best?
Posts: 1
Participants: 1