Tutorial #012: Collections API: Store documents into and fetch from Bloomreach XM using XIN mods

In this video we're going to talk about the XIN Mods Collections API. This API helps you store and fetch simple flat documents into your Bloomreach Repository.

Check out the video below.

Cheatsheet

Please find the Collections API Cheatsheet below

 

Video Code Snippet

You can see the entire new test below:

 

									const xinmods = require('xinmods');
									
									describe("using collection functions", async () => {
									
									    it("should add a document to a collection", async () => {
									
									        const conn = xinmods.connectTo("http://localhost:8080", "admin", "admin");
									
									        const collection = conn.collection("favourites");
									
									        await collection.putAndMerge("sub/my_username", {
									            recipe_id_1: false,
									            recipe_id_5: true
									        });
									
									        await collection.putAndMerge('sub/my_username', {
									            username: "my_username",
									            age: 30,
									            gender: "m"
									        });
									
									    });
									
									
									    it("can read from collection", async () => {
									
									        const conn = xinmods.connectTo("http://localhost:8080", "admin", "admin");
									
									        const collDoc = await conn.collection("favourites").get("sub/my_username");
									        console.log("collection doc: ", JSON.stringify(collDoc, null, 4));
									
									    });
									
									
									    it("can query collection", async () => {
									        const conn = xinmods.connectTo("http://localhost:8080", "admin", "admin");
									
									        const queryString = (
									            conn.newCollectionQuery('favourites')
									                .where()
									                    .equals("xinmods:gender", "m")
									                .end()
									            .build()
									        );
									
									        console.log("Query String: ", queryString);
									
									        const qResult = await conn.executeQuery(queryString);
									        console.log("Result: ", qResult.documents);
									
									    });
									
									});
									

 

Also Read