我想使用索引并看到这个:
class Products_ByCategoryName_JS extends AbstractJavaScriptIndexCreationTask {
constructor () {
super();
const { load } = this.mapUtils();
this.map("Products", product => {
return {
// Call method 'load' to load the related Category document
// The document ID to load is specified by 'product.Category'
// The Name field from the related Category document will be indexed
categoryName: load(product.Category, "Categories").Name
// Since NoTracking was Not specified,
// then any change to either Products or Categories will trigger reindexing
};
});
}
}
这就是我执行查询的方式
const matchingProducts = await session
.query({indexName: "Products/ByCategoryName"})
.whereEquals("CategoryName", "Beverages")
.all();
来自文档,好的,但是我如何执行 Products_ByCategoryName_JS 上面的索引类,
那么它在哪里执行或者我可以将它包含在我的代码中?
要将索引执行/部署到服务器,请调用:
await new Products_ByCategoryName_JS().execute(documentStore);
请参阅 Node.js 客户端中的演示“静态索引概述”:
https://demo.ravendb.net/demos/nodejs/static-indexes/static-indexes-overview