ホーム > Uncategorized > Public bookmarks 09/28/2013 (p.m.)

Public bookmarks 09/28/2013 (p.m.)


    • Let’s face it, writing MongoDB validation, casting and business logic boilerplate is a drag. That’s why we wrote Mongoose.

      var mongoose = require('mongoose'); mongoose.connect('mongodb://localhost/test');  var Cat = mongoose.model('Cat', { name: String });  var kitty = new Cat({ name: 'Zildjian' }); kitty.save(function (err) {   if (err) // ...   console.log('meow'); });

      Mongoose provides a straight-forward, schema-based solution to modeling your application data and includes built-in type casting, validation, query building, business logic hooks and more, out of the box.

    • $natural hint is telling mongo to ignore indexes on queries, it has nothing with insertions.
       please note that you cannot turn off the indexes for period of time.
       If you want to speed up your insertions, dropping your indexes is an option but it will affect your queries. a better option is to change the write concerns setting:
       for instance, "Unacknowledged" will make the insertion faster as it won’t wait for mongod to confirms the receipt of the write operation. I guess that the downside is clear.
       take a look here: http://docs.mongodb.org/manual/core/write-concern/

        

      About indexes, it’s never a good idea to have indexes that you don’t need as they are slowing down insertions (as you already know) and they are biting your machine memory.

        

      At the documentation, it is recommended to use capped collections to speed up the writes, you may want to consider it.

    • How do write operations affect indexes?

       

      Any write operation that alters an indexed field requires an update to the index in addition to the document itself. If you update a document that causes the document to grow beyond the allotted record size, then MongoDB must update all indexes that include this document as part of the update operation.

       

      Therefore, if your application is write-heavy, creating too many indexes might affect performance.

      • A covered query is a query in which:

         

           
        • all the fields in the query are part of an index, and
        •  

        • all the fields returned in the results are in the same index.
        •  

         

        Because the index “covers” the query, MongoDB can both match the query conditions and return the results using only the index; MongoDB does not need to look at the documents, only the index, to fulfill the query. An index can also cover an aggregation pipeline operation on unsharded collections.

    • To determine whether a query is a covered query, use the explain() method. If the explain() output displays true for the indexOnly field, the query is covered by an index, and MongoDB queries only that index to match the query and return the results.
    • $slice (projection)

       

       
       $slice

       

      The $slice operator controls the number of items of an array that a query returns. For information on limiting the size of an array during an update with $push, see the $slice modifier instead.

       

      Consider the following prototype query:

       

      db.collection.find( { field: value }, { array: {$slice: count } } ); 

       

       

      This operation selects the document collection identified by a field named field that holds value and returns the number of elements specified by the value of count from the array stored in the array field. If count has a value greater than the number of elements in array the query returns all elements of the array.

       

      $slice accepts arguments in a number of formats, including negative values and arrays. Consider the following examples:

       

      db.posts.find( {}, { comments: { $slice: 5 } } )

Posted from Diigo. The rest of my favorite links are here.

カテゴリー:Uncategorized
  1. まだコメントはありません。
  1. No trackbacks yet.

コメントを残す

以下に詳細を記入するか、アイコンをクリックしてログインしてください。

WordPress.com ロゴ

WordPress.com アカウントを使ってコメントしています。 ログアウト / 変更 )

Twitter 画像

Twitter アカウントを使ってコメントしています。 ログアウト / 変更 )

Facebook の写真

Facebook アカウントを使ってコメントしています。 ログアウト / 変更 )

Google+ フォト

Google+ アカウントを使ってコメントしています。 ログアウト / 変更 )

%s と連携中

%d人のブロガーが「いいね」をつけました。