Permalink
37 lines (29 sloc)
866 Bytes
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
codeql-action/tests/ml-powered-queries-repo/read-notes.js
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const mongoose = require('mongoose'); | |
Logger = require('./logger').Logger; | |
Note = require('./models/note').Note; | |
User = require('./models/user').User; | |
(async () => { | |
if (process.argv.length != 3) { | |
Logger.log("Outputs all notes visible to a user. Usage: node read-notes.js <token>") | |
return; | |
} | |
// Open the default mongoose connection | |
await mongoose.connect('mongodb://localhost:27017/notes', { useFindAndModify: false }); | |
const ownerToken = process.argv[2]; | |
const user = await User.findOne({ | |
token: ownerToken | |
}).exec(); | |
const notes = await Note.find({ | |
$or: [ | |
{ isPublic: true }, | |
{ ownerToken } | |
] | |
}).exec(); | |
notes.map(note => { | |
Logger.log("Title:" + note.title); | |
Logger.log("By:" + user.name); | |
Logger.log("Body:" + note.body); | |
Logger.log(); | |
}); | |
await mongoose.connection.close(); | |
})(); |