I try to get the actual values of entity attributes within a nodejs client but I only get the string Ids. I tried many different versions of .getValue() or asAttribute or getAttribute but just get error messages. How can I retrieve the actual values of attributes?
This is my code
export async function getMarketByTitle(title: string) {
const database = "know_graph"; // Replace this with the name of your TypeDB database
const { client, session, transaction } = await openTransaction(database);
try {
const query = `
match
$m isa market, has title "${title}", has background_information $background_information;
$m has title $m_title;
get $m, $m_title, $background_information;
`;
const iterator = await transaction.query.match(query);
let market;
for await (const answer of iterator) {
const mConcept = answer.get("m");
const mTitle = answer.get("m_title");
const backgroundInformation = answer.get("background_information");
const checkEntity = mConcept.isEntity();
const checkAttribute = mTitle.isAttribute();
market = {
id: mConcept.toString(),
title: msTitle.toString(),
backgroundInformation: backgroundInformation.toString(),
entity: checkEntity.toString(),
attribute: checkAttribute.toString
};
return market;
}```
I believe you should use
.mapand.value, like that:As per https://typedb.com/docs/clients/2.x/node-js/node-js-api-ref.html#_retrieve_value_local (updated the link for the new docs URL!).
Can't comment on James's answer, so I'll add the link to the JSON method here: https://typedb.com/docs/clients/2.x/node-js/node-js-api-ref.html#_retrieve_a_concept_as_json