重新sortingmongoose对象(实例)具有相同的顺序像相关的mongoose纲要

我使用express来创build一个web应用程序,并使用mongoose在我的应用程序中创build模型。 正如你所知,我们不能保证一个JS对象的sorting。 现在,当我使用find()或findOne()方法来查询一个特定的模型时,它返回一个JS对象,所有的东西都很好,正如我所期待的那样。 问题是,我需要返回的JS对象具有相同的我在相关的mongoose模型中定义的顺序。 考虑/models/user.js中的我的用户模型定义:

var mongoose = require('mongoose'); var user = mongoose.Schema({ local: { email: String, password: String }, firstName: String, lastName: String, role: { type: String, enum: ['admin', 'customer', 'guest'] }, address: { country: String, state: String, rest: String }, phoneNumber: String, isActive: Boolean, registeredDate: String }); 

现在,如果我使用find方法来查找具有特定电子邮件地址(已经存在于数据库中)的用户,它将返回正确的一个没有问题,但返回的对象不具有上述js mongoose模型中定义的确切顺序这是JS对象期望的)。 总之,我需要返回的对象像下面(我需要在我的应用程序中):

 { local: { email: 'someone@example.com', password: '123dfgREW' }, firstName: 'Rose', lastName: 'Marent', role: 'customer', address: { country: 'Brazil', state: 'etc', rest: 'etc' }, phoneNumber: '+654987321', isActive: true, registeredDate: '2/19/2006' } 

但它就像下面(我得到):

 { isActive: true, role: 'customer', address: { state: 'etc', country: 'Brazil', rest: 'etc' }, phoneNumber: '+654987321', lastName: 'Marent', registeredDate: '2/19/2006' firstName: 'Rose', local: { email: 'someone@example.com', password: '123dfgREW' }, } 

我怎样才能重新命令所获得的对象有秩序相同的模式使用mongoose定义模式?