1
으로 임베디드 된 문서 필드를 기반으로 복합 색인을 작성할 수있는 방법은 무엇입니까? 제목으로 말하면, 서브 문 필드를 기반으로하는 mongoose에 복합 색인을 작성하려고합니다. 이것이 내 스키마의 모양입니다.Mongoose
pricingSchema = new Schema({
\t retail:{ //normal retail price
\t \t type:Number
\t },
\t retailOnDiscount:{ //retail during solde
\t \t type:Number
\t },
\t savings:{ //price which will be saved by the customer
\t \t type:Number
\t },
\t pct_savings:{ //saving percentage
\t \t type:Number
\t }
});
ar ProductSchema = new Schema({
\t sku: {
\t type: Number
\t },
\t kind: {
\t type: String
\t },
\t title: {
\t type: String
\t }, \t
\t shipping:shippingSchema,
\t pricing:pricingSchema,
\t details:detailSchema,
\t description: {
\t type: String
\t },
\t imageUrl: {
\t type: Array
\t }
});
나는
ProductSchema.index({pricing.pct_savings:1,type:-1});
아래의 명령을 시도하지만 난이 오류를 얻을 :
/Users/willy/workspace/dev/le-beau-cheveu/dev/backend-v2/server/api/product/productModel.js:111
ProductSchema.index({pricing.pct_savings:1,type:-1});//compound index at the schema level
^
SyntaxError: Unexpected token .
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:387:25)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Module.require (module.js:367:17)
at require (internal/module.js:16:19)
at Object.<anonymous> (/Users/willy/workspace/dev/le-beau-cheveu/dev/backend-v2/server/api/product/productController.js:1:77)
at Module._compile (module.js:413:34)
at Object.Module._extensions..js (module.js:422:10)
at Module.load (module.js:357:32)
at Function.Module._load (module.js:314:12)
at Module.require (module.js:367:17)
at require (internal/module.js:16:19)
at Object.<anonymous> (/Users/willy/workspace/dev/le-beau-cheveu/dev/backend-v2/server/api/product/productRoutes.js:3:18)
at Module._compile (module.js:413:34)
아무도 도와 줄 수 있습니까? 사전에 감사드립니다.
감사합니다. – WillCed