Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: Switch to mongodb native driver #3039

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
"lokka-transport-http": "1.6.1",
"mocha": "3.2.0",
"moment": "2.19.3",
"mongojs": "2.4.0",
"mongodb": "2.1.0",
"nib": "1.1.2",
"node-env-file": "0.1.8",
"node-mandrill": "1.0.1",
Expand Down
2 changes: 1 addition & 1 deletion scripts/count.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require('node-env-file')(require('path').resolve __dirname, '../.env')
mongojs = require 'mongojs'
mongojs = require 'mongodb'
path = require 'path'
Article = require '../src/api/apps/articles/model/index.js'
env = require 'node-env-file'
Expand Down
2 changes: 1 addition & 1 deletion scripts/reindex_articles.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
require('node-env-file')(require('path').resolve __dirname, '../.env')
mongojs = require 'mongojs'
mongojs = require 'mongodb'
path = require 'path'
{ indexForSearch, indexForAlgolia, removeFromAlgolia } = Save = require '../src/api/apps/articles/model/distribute'
Article = require '../src/api/apps/articles/model/index.js'
Expand Down
2 changes: 1 addition & 1 deletion src/api/apps/articles/model/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import _ from "underscore"
import async from "async"
import { cloneDeep } from "lodash"
import { toQuery } from "./retrieve"
import { ObjectId } from "mongojs"
import { ObjectId } from "mongodb"
import moment from "moment"

const schema = require("./schema.coffee")
Expand Down
2 changes: 1 addition & 1 deletion src/api/apps/articles/model/retrieve.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { each, omit } from "lodash"
import { ObjectId } from "mongojs"
import { ObjectId } from "mongodb"

export const toQuery = input => {
const { limit, offset, sort, count } = input
Expand Down
2 changes: 1 addition & 1 deletion src/api/apps/articles/test/integration.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ObjectId } from "mongojs"
import { ObjectId } from "mongodb"
import request from "superagent"
const {
db,
Expand Down
2 changes: 1 addition & 1 deletion src/api/apps/articles/test/model/index/index.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import moment from "moment"
import { ObjectId } from "mongojs"
import { ObjectId } from "mongodb"
import rewire from "rewire"
import { extend, times } from "underscore"
const {
Expand Down
2 changes: 1 addition & 1 deletion src/api/apps/articles/test/model/index/persistence.spec.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// import rewire from "rewire"
import moment from "moment"
import { ObjectId } from "mongojs"
import { ObjectId } from "mongodb"
import { times } from "underscore"
const {
db,
Expand Down
2 changes: 1 addition & 1 deletion src/api/apps/articles/test/model/index/retrieval.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import moment from "moment"
import { ObjectId } from "mongojs"
import { ObjectId } from "mongodb"
import { pluck, times } from "underscore"
import * as Article from "../../../model"
const {
Expand Down
2 changes: 1 addition & 1 deletion src/api/apps/articles/test/model/retrieve.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ObjectId } from "mongojs"
import { ObjectId } from "mongodb"
import { toQuery } from "../../model/retrieve"

describe("Retrieve", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/api/apps/articles/test/model/save.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import moment from "moment"
import { ObjectId } from "mongojs"
import { ObjectId } from "mongodb"
import rewire from "rewire"
import sinon from "sinon"
import { times } from "underscore"
Expand Down
2 changes: 1 addition & 1 deletion src/api/apps/articles/test/routes.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ObjectId } from "mongojs"
import { ObjectId } from "mongodb"
import rewire from "rewire"
import sinon from "sinon"
import { extend } from "underscore"
Expand Down
2 changes: 1 addition & 1 deletion src/api/apps/authors/model.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
db = require '../../lib/db'
async = require 'async'
Joi = require '../../lib/joi'
{ ObjectId } = require 'mongojs'
{ ObjectId } = require 'mongodb'
{ API_MAX, API_PAGE_SIZE } = process.env

#
Expand Down
2 changes: 1 addition & 1 deletion src/api/apps/authors/test/integration.test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ _ = require 'underscore'
{ db, fixtures, fabricate, empty } = require '../../../test/helpers/db'
app = require '../../../'
request = require 'superagent'
{ ObjectId } = require 'mongojs'
{ ObjectId } = require 'mongodb'

describe 'authors endpoints', ->

Expand Down
2 changes: 1 addition & 1 deletion src/api/apps/authors/test/model.test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ _ = require 'underscore'
moment = require 'moment'
{ db, fabricate, empty, fixtures } = require '../../../test/helpers/db'
Author = require '../model'
{ ObjectId } = require 'mongojs'
{ ObjectId } = require 'mongodb'

describe 'Author', ->

Expand Down
2 changes: 1 addition & 1 deletion src/api/apps/channels/model.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ async = require 'async'
Joi = require '../../lib/joi'
moment = require 'moment'
request = require 'superagent'
{ ObjectId } = require 'mongojs'
{ ObjectId } = require 'mongodb'
{ ARTSY_URL, API_MAX, API_PAGE_SIZE } = process.env

#
Expand Down
2 changes: 1 addition & 1 deletion src/api/apps/channels/test/integration.test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ _ = require 'underscore'
{ db, fixtures, fabricate, empty } = require '../../../test/helpers/db'
app = require '../../../'
request = require 'superagent'
{ ObjectId } = require 'mongojs'
{ ObjectId } = require 'mongodb'

describe 'channels endpoints', ->

Expand Down
2 changes: 1 addition & 1 deletion src/api/apps/channels/test/model.test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ _ = require 'underscore'
moment = require 'moment'
{ db, fabricate, empty, fixtures } = require '../../../test/helpers/db'
Channel = require '../model'
{ ObjectId } = require 'mongojs'
{ ObjectId } = require 'mongodb'

describe 'Channel', ->

Expand Down
2 changes: 1 addition & 1 deletion src/api/apps/curations/model.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ async = require 'async'
Joi = require '../../lib/joi'
moment = require 'moment'
request = require 'superagent'
{ ObjectId } = require 'mongojs'
{ ObjectId } = require 'mongodb'
{ ARTSY_URL, API_MAX, API_PAGE_SIZE } = process.env

OPTIONS = { allowUnknown: true, stripUnknown: false }
Expand Down
2 changes: 1 addition & 1 deletion src/api/apps/curations/test/integration.test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ _ = require 'underscore'
{ db, fixtures, fabricate, empty } = require '../../../test/helpers/db'
app = require '../../../'
request = require 'superagent'
{ ObjectId } = require 'mongojs'
{ ObjectId } = require 'mongodb'

describe 'curations endpoints', ->

Expand Down
2 changes: 1 addition & 1 deletion src/api/apps/curations/test/model.test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ _ = require 'underscore'
moment = require 'moment'
{ db, fabricate, empty, fixtures } = require '../../../test/helpers/db'
Curations = require '../model'
{ ObjectId } = require 'mongojs'
{ ObjectId } = require 'mongodb'

describe 'Curations', ->

Expand Down
2 changes: 1 addition & 1 deletion src/api/apps/graphql/resolvers.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ const {
presentCollection,
find,
} = require("api/apps/articles/model/index.js")
const { ObjectId } = require("mongojs")
const { ObjectId } = require("mongodb")

export const articles = (root, args, req, ast) => {
const unpublished = !args.published || args.scheduled
Expand Down
2 changes: 1 addition & 1 deletion src/api/apps/graphql/test/resolvers.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import {
SeriesArticle,
StandardArticle,
} from "@artsy/reaction/dist/Components/Publishing/Fixtures/Articles"
import { ObjectId } from "mongojs"
import { ObjectId } from "mongodb"
import * as resolvers from "../resolvers"
const { fixtures } = require("api/test/helpers/db.coffee")

Expand Down
2 changes: 1 addition & 1 deletion src/api/apps/sections/model.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ async = require 'async'
Joi = require '../../lib/joi'
moment = require 'moment'
request = require 'superagent'
{ ObjectId } = require 'mongojs'
{ ObjectId } = require 'mongodb'
{ ARTSY_URL, API_MAX, API_PAGE_SIZE } = process.env

#
Expand Down
2 changes: 1 addition & 1 deletion src/api/apps/sections/test/integration.test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ _ = require 'underscore'
{ db, fixtures, fabricate, empty } = require '../../../test/helpers/db'
app = require '../../../'
request = require 'superagent'
{ ObjectId } = require 'mongojs'
{ ObjectId } = require 'mongodb'

describe 'sections endpoints', ->

Expand Down
2 changes: 1 addition & 1 deletion src/api/apps/sections/test/model.test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ _ = require 'underscore'
moment = require 'moment'
{ db, fabricate, empty, fixtures } = require '../../../test/helpers/db'
Section = require '../model'
{ ObjectId } = require 'mongojs'
{ ObjectId } = require 'mongodb'

describe 'Section', ->

Expand Down
2 changes: 1 addition & 1 deletion src/api/apps/tags/model.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ _ = require 'underscore'
db = require '../../lib/db'
async = require 'async'
Joi = require '../../lib/joi'
{ ObjectId } = require 'mongojs'
{ ObjectId } = require 'mongodb'
{ API_MAX, API_PAGE_SIZE } = process.env

#
Expand Down
2 changes: 1 addition & 1 deletion src/api/apps/tags/test/integration.test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ _ = require 'underscore'
{ db, fixtures, fabricate, empty } = require '../../../test/helpers/db'
app = require '../../../'
request = require 'superagent'
{ ObjectId } = require 'mongojs'
{ ObjectId } = require 'mongodb'

describe 'tags endpoints', ->

Expand Down
2 changes: 1 addition & 1 deletion src/api/apps/tags/test/model.test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ _ = require 'underscore'
moment = require 'moment'
{ db, fabricate, empty, fixtures } = require '../../../test/helpers/db'
Tag = require '../model'
{ ObjectId } = require 'mongojs'
{ ObjectId } = require 'mongodb'

describe 'Tag', ->

Expand Down
2 changes: 1 addition & 1 deletion src/api/apps/users/model.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ db = require '../../lib/db'
request = require 'superagent'
async = require 'async'
bcrypt = require 'bcryptjs'
{ ObjectId } = require 'mongojs'
{ ObjectId } = require 'mongodb'
{ ARTSY_URL, SALT, API_URL } = process.env
jwtDecode = require 'jwt-decode'

Expand Down
2 changes: 1 addition & 1 deletion src/api/apps/users/test/integration.test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ _ = require 'underscore'
{ db, fixtures, fabricate, empty } = require '../../../test/helpers/db'
app = require '../../../'
request = require 'superagent'
{ ObjectId } = require 'mongojs'
{ ObjectId } = require 'mongodb'

describe 'GET /api/users/me', ->

Expand Down
2 changes: 1 addition & 1 deletion src/api/apps/users/test/model.test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ sinon = require 'sinon'
rewire = require 'rewire'
{ db, fabricate, empty, fixtures } = require '../../../test/helpers/db'
User = rewire '../model'
{ ObjectId } = require 'mongojs'
{ ObjectId } = require 'mongodb'
gravity = require('@artsy/antigravity').server
gravityFabricate = require('@artsy/antigravity').fabricate
express = require 'express'
Expand Down
2 changes: 1 addition & 1 deletion src/api/apps/users/test/routes.test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ _ = require 'underscore'
sinon = require 'sinon'
rewire = require 'rewire'
routes = rewire '../routes'
{ ObjectId } = require 'mongojs'
{ ObjectId } = require 'mongodb'

describe 'routes', ->

Expand Down
2 changes: 1 addition & 1 deletion src/api/apps/verticals/model.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ _ = require 'underscore'
db = require '../../lib/db'
async = require 'async'
Joi = require '../../lib/joi'
{ ObjectId } = require 'mongojs'
{ ObjectId } = require 'mongodb'
{ API_MAX, API_PAGE_SIZE } = process.env

#
Expand Down
2 changes: 1 addition & 1 deletion src/api/apps/verticals/test/integration.test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ _ = require 'underscore'
{ db, fixtures, fabricate, empty } = require '../../../test/helpers/db'
app = require '../../../'
request = require 'superagent'
{ ObjectId } = require 'mongojs'
{ ObjectId } = require 'mongodb'

describe 'verticals endpoints', ->

Expand Down
2 changes: 1 addition & 1 deletion src/api/apps/verticals/test/model.test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ _ = require 'underscore'
moment = require 'moment'
{ db, fabricate, empty, fixtures } = require '../../../test/helpers/db'
Vertical = require '../model'
{ ObjectId } = require 'mongojs'
{ ObjectId } = require 'mongodb'

describe 'Vertical', ->

Expand Down
11 changes: 4 additions & 7 deletions src/api/lib/db.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,21 @@
# on the folder names under /apps. https://github.com/mafintosh/mongojs
#

mongojs = require 'mongojs'
mongojs = require 'mongodb'
fs = require 'fs'
path = require 'path'
{ MONGOHQ_URL } = process.env
debug = require('debug') 'api'

collections = ['articles', 'users', 'sections', 'artists', 'curations', 'channels', 'tags', 'verticals', 'authors', 'sessions']
db = mongojs MONGOHQ_URL, collections
#db = mongojs MONGOHQ_URL, collections
db = new mongojs.Db MONGOHQ_URL, collections
console.info(db.listDatabases())

exit = (msg) -> (err) ->
debug msg
debug msg, err if msg is 'Mongo Error'
process.exit(1)

db.on 'close', exit('Mongo Connection Closed')
db.on 'error', exit('Mongo Error')

db.createCollection('sessions', {})

module.exports = db
module.exports.collections = collections
2 changes: 1 addition & 1 deletion src/api/lib/joi.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Joi = require('joi')
{ ObjectId } = require 'mongojs'
{ ObjectId } = require 'mongodb'

customJoi = Joi.extend(
base: Joi.string()
Expand Down
18 changes: 14 additions & 4 deletions src/api/test/helpers/db.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,17 @@ fixturize = (collection, data) ->
data

@empty = (callback) =>
@db.getCollectionNames (err, names) =>
return callback() if names.length is 0
cb = _.after names.length, callback
@db.collection(col).drop(cb) for col in names
console.log("show db attr", @db.collections)
return callback()

# for collectionsId, collectionsName of @db.collections
# console.info('show a db func', @db.articles)
# return callback() if @db.collections[collectionsId].length is 0
# cb = _.after @db.collections[collectionsId].length, callback
# console.info('all collections', @db.collections[collectionsId])
# @db.collections[collectionsId].remove(cb)

# @db.collections (err, collections) =>
# return callback() if names.length is 0
# cb = _.after names.length, callback
# @db.collection(col).drop(cb) for col in names
2 changes: 1 addition & 1 deletion src/test/helpers/fixtures.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
User = require '../../client/models/user'
{ ObjectId } = require 'mongojs'
{ ObjectId } = require 'mongodb'
moment = require 'moment'


Expand Down
Loading