Issue with Integration test for Projection

Hi,
I started the M220 course quite late thats why posting this issue from last week’s ticket.
I successfully implemented and ran unit test for the Ticket: Projection but when I ran Integration test on the status page it says “Projection: The return from the api was incorrect when searching by country”. I cant figure out how can I debug this problem.
I ran my query in mongo shell and it returned the expected values which resulted in passing the unit tests. But I cant figure out why it is not passing the integration test.
Capture1
Any help would be much appreciated.
Thank you.Capture
Capture3
Stack Trace when I click on Projection on status page:
(node:14696) UnhandledPromiseRejectionWarning: TypeError: Converting
circular structure to JSON
at JSON.stringify ()
at stringify (C:\Users\Toshiba\Documents\Node Course\mflix\node_modules\express\lib\response.js:1123:12)
at ServerResponse.json (C:\Users\Toshiba\Documents\Node Course\mflix\node_modules\express\lib\response.js:260:14)
at json (C:\Users\Toshiba\Documents\Node Course\mflix\src\api/movies.controller.js:25:9)
at tryCatch (C:\Users\Toshiba\Documents\Node Course\mflix\node_modules\regenerator-runtime\runtime.js:45:40)
at Generator.invoke [as _invoke] (C:\Users\Toshiba\Documents\Node Course\mflix\node_modules\regenerator-runtime\runtime.js:271:22)
at Generator.prototype.(anonymous function) [as next] (C:\Users\Toshiba\Documents\Node Course\mflix\node_modules\regenerator-runtime\runtime.js:97:21)
at asyncGeneratorStep (C:\Users\Toshiba\Documents\Node Course\mflix\node_modules@babel\runtime\helpers\asyncToGenerator.js:3:24)

hi @mubeenullhaq,

Please take a look at Projection Ticket post and let me know if it helps.

Kanika

Hi @Kanika
Can you please elaborate a little bit more as I used the syntax for projection in my query from a lesson called basic-reads.spec.js. Which is as follows:
let result = await movies.findOne(
{ cast: filter },
{ projection: { title: 1, year: 1 } },
)
I am using the same way to handle projection in my query. My query is as follows:
let result = await movies.find(
{ countries: { $in: countries } },
{ projection: { title: 1 } },
)
Is there any syntactical issue with my query?

As per your guidance I have used the project method in my query. My updated query is as follows:
let result = await movies.find(
** { countries: { $in: countries } })**
** .project({title:1})**
Still cant pass integration test on the status page.
I have tried to log ‘result’ on the console and it logs some cursor information. not the actual document.
console.log(result) displays:
console.log src/dao/moviesDAO.js:63
Cursor {
_readableState:
ReadableState {
objectMode: true,
highWaterMark: 16,
buffer: BufferList { head: null, tail: null, length: 0 },
length: 0,
pipes: null,
pipesCount: 0,
flowing: null,
ended: false,
endEmitted: false,
reading: false,
sync: true,
needReadable: false,
emittedReadable: false,
readableListening: false,
resumeScheduled: false,
paused: true,
emitClose: true,
destroyed: false,
defaultEncoding: ‘utf8’,
awaitDrain: 0,
readingMore: false,
decoder: null,
encoding: null },
readable: true,
_events: [Object: null prototype] {},
_eventsCount: 0,
_maxListeners: undefined,
operation:
FindOperation {
options:
{ skip: 0,
limit: 0,
raw: undefined,
hint: null,
timeout: undefined,
slaveOk: true,
readPreference: [ReadPreference],
db: [Db],
promiseLibrary: [Function: Promise] },
ns:
MongoDBNamespace { db: ‘sample_mflix’, collection: ‘movies’ },
cmd:
{ find: ‘sample_mflix.movies’,
limit: 0,
skip: 0,
query: [Object],
raw: undefined,
hint: null,
timeout: undefined,
slaveOk: true,
readPreference: [ReadPreference],
fields: [Object] },
cursorState:
{ cursorId: null,
cmd: [Object],
documents: ,
cursorIndex: 0,
dead: false,
killed: false,
init: false,
notified: false,
limit: 0,
skip: 0,
batchSize: 1000,
currentLimit: 0,
transforms: undefined,
raw: undefined } },
pool: null,
server: undefined,
disconnectHandler: undefined,
bson: BSON {},
ns: ‘sample_mflix.movies’,
namespace:
MongoDBNamespace { db: ‘sample_mflix’, collection: ‘movies’ },
cmd:
{ find: ‘sample_mflix.movies’,
limit: 0,
skip: 0,
query: { countries: [Object] },
raw: undefined,
hint: null,
timeout: undefined,
slaveOk: true,
readPreference: ReadPreference { mode: ‘primary’, tags: undefined },
fields: { title: 1 } },
options:
{ skip: 0,
limit: 0,
raw: undefined,
hint: null,
timeout: undefined,
slaveOk: true,
readPreference: ReadPreference { mode: ‘primary’, tags: undefined },
db:
Db {
_events: [Object: null prototype] {},
_eventsCount: 0,
_maxListeners: undefined,
s: [Object],
serverConfig: [Getter],
bufferMaxEntries: [Getter],
databaseName: [Getter] },
promiseLibrary: [Function: Promise] },
topology:
NativeTopology {
_events:
[Object: null prototype] {
topologyDescriptionChanged: [Array],
authenticated: [Function],
error: [Array],
timeout: [Array],
close: [Array],
parseError: [Array],
fullsetup: [Array],
all: [Array],
reconnect: [Array],
serverOpening: [Function],
serverDescriptionChanged: [Function],
serverHeartbeatStarted: [Function],
serverHeartbeatSucceeded: [Function],
serverHeartbeatFailed: [Function],
serverClosed: [Function],
topologyOpening: [Function],
topologyClosed: [Function],
commandStarted: [Function],
commandSucceeded: [Function],
commandFailed: [Function],
joined: [Function],
left: [Function],
ping: [Function],
ha: [Function],
open: [Function] },
_eventsCount: 25,
_maxListeners: undefined,
s:
{ id: 0,
options: [Object],
seedlist: [Array],
description: [TopologyDescription],
serverSelectionTimeoutMS: 10000,
heartbeatFrequencyMS: 30000,
minHeartbeatIntervalMS: undefined,
Cursor: [Function: Cursor],
bson: BSON {},
servers: [Map],
sessionPool: [ServerSessionPool],
sessions: ,
promiseLibrary: [Function: Promise],
credentials: [MongoCredentials],
clusterTime: [Object],
monitorTimers: [Array],
iterationTimers: ,
clientInfo: [Object],
srvPoller: [SrvPoller],
detectTopologyDescriptionChange: [Function],
connected: true,
sCapabilities: [ServerCapabilities] } },
cursorState:
{ cursorId: null,
cmd:
{ find: ‘sample_mflix.movies’,
limit: 0,
skip: 0,
query: [Object],
raw: undefined,
hint: null,
timeout: undefined,
slaveOk: true,
readPreference: [ReadPreference],
fields: [Object] },
documents: ,
cursorIndex: 0,
dead: false,
killed: false,
init: false,
notified: false,
limit: 0,
skip: 0,
batchSize: 1000,
currentLimit: 0,
transforms: undefined,
raw: undefined },
logger: Logger { className: ‘Cursor’ },
s:
{ numberOfRetries: 5,
tailableRetryInterval: 500,
currentNumberOfRetries: 5,
state: 0,
promiseLibrary: [Function: Promise],
currentDoc: null,
explicitlyIgnoreSession: false } }

hey i hope you have found your solution if not then please look at care fully at your query that is hint $in method take an array {$in:[ ] } and and if you are giving multiple argument then how will u manage (spread parameter) please try if it does not work let me know i will post the code good luck

Hey @KRISHN_MOHAN_64661 Thank you for your kind help. Actually I was using {[]} in my query before but It was resulting in unit test failure. Because the unit test was passing it an array of countries already. Using {[]} in the query made it an 2d array. “countries is an array itself” .!
You may see the result yourself:
Capture|638x500

thats why i told you about spread** […countries**] i hope you got the hint honestly following others direction that how you should write the code so given input is justified is difficult and it is time consuming so check the output of test and match that which kind of input they are expecting this will save you lot of time and you will enjoy understanding their way of writing code and how you could have written .good luck

hey @KRISHN_MOHAN_64661 can you please describe what you said in hindi. It would be much easier for me to understand your point. My English is not that good.
Mai kafi dafa apka last comment perha hai lekin thk sy smj ni aia. I hope you understand.

no worry my english is also not that good .by the way i am stuck in usermanagement ticket can u give me the hint i have wasted so much time already .aur hann mai hindi me baat kar sakta hun but we should try in english even it is little bit wrong thnak you

Hi @KRISHN_MOHAN_64661,

Please describe your issues one by one so that I can help you better.

You need to use .project({...}) function.

Also, we encourage everyone to share the information in common language to support better. :slight_smile:

Kanika