I am migrating the API to TypeORM from mongoose. I have an array(conversationIds) containing list of id to be searched from the Database and it should return me the available id. Below are the query which i have tried.
const conversationMessagesWithDuplicates = await consversationRepository.createQueryBuilder("conversation").where("conversation.channel_message_ID = :channel_message_ID",{channel_message_ID : conversationIds}).getMany();
and also this one
const conversationMessagesWithDuplicates = await consversationRepository.find({channel_message_ID: conversationIds});
But i am getting below issue:
(node:11548) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): QueryFailedError: Error: Incorrect syntax near ','.
I have tried using entity Manger also but no success
const conversationMessagesWithDuplicates = await entityManager.query(`SELECT channel_message_ID FROM Conversation where channel_message_ID IN (conversationIds)`);
Below is the MoongoseAPI which is working fine:
Conversation.find( { channel_message_ID: { $in: conversationMessageIdArray } } ).exec(function(err, conversationMessagesDuplicatesArray) {}
This is the solution
const conversationMessagesWithDuplicates = await consversationRepository.createQueryBuilder("conversation").where("conversation.channel_message_ID IN (:conversationIds)", { conversationIds: conversationIds }).getMany();