跟进这个1岁的帖子:
Mongodb mongoid model attributes sorted by alphabetical order not insertion order
我有一个使用mongoid v.3.0.0的rails 3.2.8应用程序。我的应用程序偶尔会在数据库对象(例如产品)上使用“update_attribute”函数,但是当它执行时,所有属性都会按字母顺序重新排序。
当我在控制台中复制它时,它看起来像这样:
1.9.3-p385 :001 > product = Product.find("5156bc9b83c3368121000008")
=> [#<Product _id: 5156bc9b83c3368121000008, _type: nil, product_number: "123", product_name: "Some product name", long_description: "<P>Some long product description.</P>", vendor_number: "abc", language_i_d: "1234", currency_i_d: "USD", category_number: "1", image_link: "http://some-external-website.com/image-path.jpg", original_id: "123456">]
1.9.3-p385 :002 > product.update_attribute(:image_link, "http://my-own-website.com/image-path.jpg")
=> true
1.9.3-p385 :003 > exit
我现在再次启动控制台(出于某种原因,我需要在显示新订单之前退出并重新打开控制台):
1.9.3-p385 :001 > product = Product.find("5156bc9b83c3368121000008")
=> [#<Product _id: 5156bc9b83c3368121000008, _type: nil, category_number: "1", currency_i_d: "USD", image_link: "http://my-own-website.com/image-path.jpg", language_i_d: "1234", long_description: "<P>Some long product description.</P>", original_id: "123456", product_name: "Some product name", product_number: "123", vendor_number: "abc">]
有谁知道如何避免重新排序?