我想使用一个索引,然后看到了这个:
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上面的索引类,
那么它在哪里执行,或者我可以在我的代码中的哪里包含它呢?
EURO:收到此错误:
InvalidArgumentException: Map is required to generate an index, you cannot create an index without a valid Map property (in index Users/ByName)
索引:
// @ts-nocheck
import { AbstractJavaScriptIndexCreationTask } from "ravendb";
export class Users_ByName extends AbstractJavaScriptIndexCreationTask<{name: string}[]> {
constructor () {
super();
this.map = `
from users in docs.UsersData
select new {
Name = users.name
}`;
}
}
帖子主题:回复:
app.get('/', async (req, res) => {
try {
await new Users_ByName().execute(store);
let session = store.openSession();
const queryOnIndex = session.query({indexName: 'UsersData/ByName'}).whereEquals('name', 'Johnse');
const d = await queryOnIndex.all();
res.json('s');
} catch(e) {
console.log(e);
res.send(e);
}
});
我做错了什么? 我的集合名称是UsersData,我的字段名称是我想要索引的名称