Slackbot
07/28/2023, 8:05 PMKanak Arora
07/28/2023, 8:08 PMconst array = (length, items) => Array(length).fill(0).map(items);
await client.collections().create({
name: "Products",
fields: [
{ name: "product_idx", type: "string" },
{ name: "product_name", type: "string" },
],
});
await client.collections().create({
name: "Users",
fields: [
{ name: "user_id", type: "string" },
{ name: "user_name", type: "string" },
],
});
await client.collections().create({
name: "CustomerProductPrices",
fields: [
{ name: "user_id", type: "string", reference: "Users.user_id" },
{ name: "product_id", type: "string", reference: "Products.product_idx" },
{ name: "product_price", type: "float" },
],
});
let products = array(200, () => ({
product_idx: chance.guid(),
product_name: chance.sentence({
words: chance.integer({ min: 1, max: 10 }),
}),
}));
let users = array(200, () => ({
user_id: chance.guid(),
user_name: chance.word(),
}));
let customers = array(200, () => ({
user_id: users[chance.integer({ min: 0, max: users.length - 1 })].user_id,
product_id:
products[chance.integer({ min: 0, max: products.length - 1 })].product_idx,
product_price: chance.floating({ fixed: 2, min: 1 }),
}));
await client
.collections("Products")
.documents()
.import(products, { action: "create" });
await client
.collections("Users")
.documents()
.import(users, { action: "create" });
await client
.collections("CustomerProductPrices")
.documents()
.import(customers, { action: "create" });
let result = await client
.collections("Products")
.documents()
.search({
q: "*",
filter_by: `$CustomerProductPrices(user_id:=${customers[0].user_id})`,
include_fields: `$CustomerProductPrices(product_price)`,
});
As is, this query is hanging. If I change "product_idx" to "product_id" (so that referencing field matches), or if I change the collection being searched to "Users", the query works fine.Ahmed Hableel
07/28/2023, 9:16 PMError importing document: Field `category_id_sequence_id` has been declared in the schema, but is not found in the document
field name is category_id for both collectionsAhmed Hableel
07/28/2023, 9:55 PMKishore Nallan
07/31/2023, 10:34 AM