MongoDB (PHP) - user id and OrderWith number

First I will say that I am new to MongoDb and document oriented db in general.

After some problems with embedded documents in mongodb (it is not possible to select only a subdocument (an example of one comment in a blog post)), I reworked db. Now I have two collections, posts and comments (and not a real deal, using a sample blog for convenience).

Example: a document with a collection of records:

Array {

'_id'   :  MongoId,

'title' : 'Something',

'body'  : 'Something awesome'   

}

An example is a comment:

Array {

'_id'    : MongoId,

'postId' : MongoId,

'userId' : MongoId,

'commentId' : 33,

'comment' : 'Punch the punch line!'

}

As you can see, I have several documents with comments (as I said, I want to be able to select one comment, not an array).

: , postId commentId (commentId - postId). Oh commentId int, , "orderWith".

:

URI: mongo.php? post = 4de526b67cdfa94f0f000000 & comment = 4

: $comment = $collection- > findOne (array ( "postId" = > $theObjId, "commentId" = > (int) $commentId));

.

  • ?
  • ?
  • , commentId postId (upsert?)?
  • ?
+3
2

?

. ? , ?

MongoDB "" " ". , .

? , commentId postId (upsert?)?

. (, ), . .

ObjectId/MongoId. .

. findAndModify. "last_comment_id" , .

?

? .

? , .

+3

, The Big Picture , .

, . , . . CommentID CreatedAt .

, .

+2

All Articles