Database Reference
In-Depth Information
Create and edit content nodes
The most common operations inside of a CMS center on creating and editing content. Con-
sider the following insert operation:
db . cms . nodes . insert ({
'metadata' : {
'nonce' : ObjectId (),
'parent_id' : ObjectId ( ... ),
'slug' : '2012-03-noticed-the-news' ,
'type' : 'blog-entry' ,
'title' : 'Noticed in the News' ,
'created' : datetime . utcnow (),
'author' : { 'id' : user_id , 'name' : 'Rick' },
'tags' : [ 'news' , 'musings' ],
'detail' : {
'publish_on' : datetime . utcnow (),
'text' : 'I noticed the news from Washington today…' }
}
})
One field that we've used but not yet explained is the nonce field. A nonce is a value that is
designed to be only used once. In our CMS, we've used a nonce to mark each node when it is
inserted or updated. This helps us to detect problems where two users might be modifying the
same node simultaneously. Suppose, for example, that Alice and Bob both decide to update
the About page for their CMS, and the sequence goes something like this ( Figure 6-1 ):
1. Alice saves her changes. The page refreshes, and she sees her new version.
2. Bob then saves his changes. The page refreshes, and he sees his new version.
3. Alice and Bob both refresh the page. Both of them see Bob's version. Alice's version
has been lost, and Bob didn't even know he was overwriting it!
Search WWH ::




Custom Search